package LanQiao;

import java.util.Scanner;

public class Demo6 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int n = 0, m = 0;

        n = scanner.nextInt();
        m = scanner.nextInt();

        int[][] nums = new int[n + 2][m + 2];

        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < m + 1; j++) {
                nums[i][j] = scanner.nextInt();
            }
        }

        int max = 0x3f3f3f3f * (-1);

        for (int i = 1; i < n + 1; i++) {
            for (int j = 1; j < m + 1; j++) {
                int temp = nums[i][j] + nums[i - 1][j] + nums[i + 1][j] + nums[i][j - 1] + nums[i][j + 1];
                max = Math.max(max, temp);
            }
        }

        System.out.println(max);
    }
}
